<template>
  <nm-container>
    <el-form label-width="80px" :inline="true" style="background:white; padding:20px">
      <el-form-item label="当前票号" prop="station_id">
        <el-input v-model="currentTicketNum" />
      </el-form-item>
      <el-button type="primary" @click="modification">修改当前票号</el-button>
      <el-button type="primary" v-if="start" @click="alter">启用票号</el-button>
      <el-button type="primary" v-if="forbidden" @click="alter">禁用票号</el-button>
    </el-form>
    <div class="Dh_table">
      <el-table highlight-current-row :max-height="height" @current-change="handleCurrentChange" ref="topictable" :data="getList" border align="center" :header-cell-style="{ 'text-align': 'center', 'font-weight': 'bold', color: '#030202' }" :cell-style="{ 'text-align': 'center' }" style="width: 100%;text-align: center;">
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <span>{{ scope.row.status == 0 ? '禁用' : scope.row.status == 1 ? '启用' : '作废' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="startTicketNum" label="起始票号"> </el-table-column>
        <el-table-column prop="endTicketNum" label="截至票号"> </el-table-column>
        <el-table-column prop="currentTicketNum" label="当前票号"> </el-table-column>
        <el-table-column prop="remainTicket" label="余量"> </el-table-column>
      </el-table>
    </div>

    <el-pagination background layout="prev, pager, next" :total="total / 10" />
  </nm-container>
</template>
<script>
import { mixins } from 'netmodular-ui'
import page from './page'

const api = $api.dispatch.passenger_ticket

export default {
  name: page.name,
  mixins: [mixins],
  data() {
    return {
      currentTicketNum: '',
      getList: [],
      total: '',
      height: 400,
      start: true,
      forbidden: false,
      id: '',
      status: false,
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.height = window.innerHeight - this.$refs.topictable.$el.offsetTop - 150
    })
    this.getCurrentuserbill()
  },
  methods: {
    handleCurrentChange(data) {
      this.currentTicketNum = data.currentTicketNum
      this.id = data.id
      if (data.status == 0) {
        this.status = true
        this.start = true
        this.forbidden = false
      } else {
        this.status = false
        this.start = false
        this.forbidden = true
      }
    },
    // 获取当前登录用户票号
    getCurrentuserbill() {
      api.querycurrentuserbill({ status: 99 }).then((res) => {
        this.getList = res
      })
    },
    //修改当前票号状态
    alter() {
      if (this.id == '') {
        this.$message({
          message: '请选择一条数据',
          type: 'warning',
        })
      } else {
        api.changebillstatus({ id: this.id, status: this.status == true ? 1 : 0 }).then((res) => {
          this.id = ''
          this.getCurrentuserbill()
          this.$message({
            message: '修改成功',
            type: 'success',
          })
          console.log(res)
        })
      }
    },
    // 修改当前票号
    modification() {
      api.changecurrentbillnum({ id: this.id, currentTicketNum: this.currentTicketNum }).then((res) => {
        console.log(res)
        this.getCurrentuserbill()
        this.currentTicketNum = ''
        this.$message({
          message: '修改成功',
          type: 'success',
        })
      })
    },
  },
}
</script>

<style>
/* .Dh_table .el-table__body tr.current-row > td {
  background-color: #6eadff !important;
  color: #fff;
} */
</style>
